package com.gba.mark.labelResult.controller;

import com.alibaba.fastjson.JSONObject;
import com.gba.mark.group.service.IGroupService;
import com.gba.mark.labelResult.entity.dto.LabelResultDTO;
import com.gba.mark.labelResult.service.ILabelResultService;
import com.gba.mark.user.service.user.IUserService;
import com.gba.mark.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/label/result")
public class LabelResultController {

    @Autowired
    private ILabelResultService labelResultService;

    @Autowired
    private IUserService userService;

    @Autowired
    private IGroupService groupService;

    @GetMapping("/count")
    public ResponseUtil<JSONObject> getCount(Authentication authentication){
        String username = authentication.getName();
        JSONObject count = labelResultService.count(username);
        return new ResponseUtil<>(HttpStatus.OK, "", count);
    }

    @PostMapping("/submit")
    public ResponseUtil submit(Authentication authentication ,
//                               @RequestParam String groupName,
                               @RequestBody LabelResultDTO labelResultDTO){
        int userId = userService.getUserIdByAuth(authentication);
//        int groupId = groupService.getGroupIdByAuthAndName(authentication, groupName);
        return new ResponseUtil<>(HttpStatus.OK,"",labelResultService.submit(labelResultDTO, userId));

    }
}
